<?php require_once('Connections/morroco.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['nombre'])) {
  $loginUsername=$_POST['nombre'];
  $password=$_POST['clave'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "menu.php";
  $MM_redirectLoginFailed = "index.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_morroco, $morroco);
  
  $LoginRS__query=sprintf("SELECT nombre, clave FROM usuarios WHERE nombre=%s AND clave=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $morroco) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/principal2.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<link rel="icon" type="image/x-icon" href="imagenes/favicon.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Ingreso al Sistema</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="css/twoColFixLtHdr.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.container .header h1 strong {
	color: #FFF;
}
</style>
</head>

<body>

<div class="container">
  <div class="header">
    <h1>Generador de Horarios</h1>
  <!-- end .header --></div>
  <div class="sidebar1">
    <ul class="nav">
      <li><a href="menu.php">Inicio / Menú</a></li>
    </ul>
    <p><img src="imagenes/morroco.png" width="149" height="94" alt="morroco" /></p>
    <!-- end .sidebar1 --></div>
  <div class="content"> <!-- InstanceBeginEditable name="EditRegion3" -->
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="center" valign="middle"><p><strong>Ingreso al Sistema</strong></p>
        <p>&nbsp;</p>
        <form id="conectar" name="conectar" method="POST" action="<?php echo $loginFormAction; ?>">
          <table width="40%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="33%" align="right">Nombre:</td>
              <td width="67%"><label for="nombre"></label>
                <input style="text-align:center" name="nombre" type="text" id="nombre" size="50" placeholder="Ingrese el Nombre" required="required" /></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td align="right">Clave:</td>
              <td><input style="text-align:center" name="clave" type="password" id="clave" size="50" placeholder="Ingrese la Clave" required="required" /></td>
            </tr>
            <tr>
              <td colspan="2" align="center">&nbsp;</td>
            </tr>
            <tr>
              <td colspan="2" align="center"><input type="submit" name="button" id="button" value="Ingresar" /></td>
              </tr>
          </table>
          <p>&nbsp;</p>
          
        </form>
        <p>&nbsp;</p>
        <p>&nbsp;</p></td>
      </tr>
    </table>
    <p>&nbsp;</p>
  <!-- InstanceEndEditable -->    <!-- end .content --></div>
  <div class="footer">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" valign="middle"><a href="http://www.ch0ngu1.com" target="new">www.Ch0nGu1.com</a></td>
  </tr>
</table>
    <!-- end .footer --></div>
  <!-- end .container --></div>
</body>
<!-- InstanceEnd --></html>
